package com.xm.controller;

import com.xm.common.pojo.JsonResult;
import com.xm.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@CrossOrigin
@RequestMapping(value = "/order/")
@RestController()
public class OrderController {
    @Autowired
    OrderService orderService;

    @PostMapping("{userName}/{itemId}/{num}")
    JsonResult saveOrder(@PathVariable String userName,
                         @PathVariable Integer itemId,
                         @PathVariable Integer num){
        orderService.saveOrder(userName,itemId,num);
        return new JsonResult("订单生成成功");
    }

    @DeleteMapping("{orderId}")
    JsonResult deleteOrder(@PathVariable Integer orderId){
        orderService.deleteOrder(orderId);
        return new JsonResult("订单删除成功");
    }

    @GetMapping("{username}")
    JsonResult findOrder(@PathVariable String username){
        return new JsonResult(orderService.findOrderByUserName(username));
    }




}
